/*
 * @lc app=leetcode.cn id=2283 lang=typescript
 *
 * [2283] 判断一个数的数字计数是否等于数位的值
 */

// @lc code=start
function digitCount(num: string): boolean {
    const cache = new Map<string, number>();
    for (let i = 0; i < num.length; i++) {
        const element = num[i];
        cache.set(element, (cache.get(element) || 0) + 1);
    }
    for (let i = 0; i < num.length; i++) {
        const element = num[i];
        if ((cache.get(i.toString()) || 0).toString() !== element) return false;
    }
    return true;
}
// @lc code=end
